import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom/client';

    
class Example extends React.Component {
    constructor() {
        super();
        this.state = {
            val: 0,
        };
    }

    componentDidMount() {
        this.setState({ val: this.state.val + 1 });
        console.log(this.state.val);
        this.setState({ val: this.state.val + 1 });
        console.log(this.state.val);

        setTimeout(() => {
            this.setState({ val: this.state.val + 1 });
            console.log(this.state.val);
            this.setState({ val: this.state.val + 1 });
            console.log(this.state.val);
        }, 0);
    }

    render() {
        return null;
    }
}

// function showFullName(user) {
//     return user.firtName + ' ' +  user.lastName;
// }
// const user = {
//     firtName: '11',
//     lastName: '22'
// }
// const element = (
//     <h1>
//         Hello, {showFullName(user)}
//     </h1>
// )

// ReactDOM.render(
//     element,
//     document.getElementById('root')
// );




/*
_processPendingState: function (props, context) {
    var inst = this._instance;
    var queue = this._pendingStateQueue;
    var replace = this._pendingReplaceState;
    this._pendingReplaceState = false;
    this._pendingStateQueue = null;
        if (!queue) {
        return inst.state;
        }
    
        if (replace && queue.length === 1) {
        return queue[0];
        }
    
        var nextState = _assign({}, replace ? queue[0] : inst.state);
        for (var i = replace ? 1 : 0; i < queue.length; i++) {
        var partial = queue[i];
        _assign(nextState, typeof partial === 'function' ? partial.call(inst, nextState, props, context) : partial);
        }
    
    return nextState;
},


*/

function FiberNode(
    tag: WorkTag,
    pendingProps: mixed,
    key: null | string,
    mode: TypeOfMode,
  ) {
    // 作为静态数据结构的属性
    this.tag = tag;
    this.key = key;
    this.elementType = null;
    this.type = null;
    this.stateNode = null;
  
    // 用于连接其他Fiber节点形成Fiber树
    this.return = null;
    this.child = null;
    this.sibling = null;
    this.index = 0;
    this.ref = null;
  
    // 动态工作单元的属性
    this.pendingProps = pendingProps;
    this.memoizedProps = null;
    this.updateQueue = null;
    this.memoizedState = null;
    this.dependencies = null;
  
    this.mode = mode;
    this.effectTag = NoEffect;
    this.nextEffect = null;
    this.firstEffect = null;
    this.lastEffect = null;
  
    // 调度优先级相关
    this.lanes = NoLanes;
    this.childLanes = NoLanes;
  
    // 指向该fiber在另一次更新时对应的fiber
    this.alternate = null;
  }



function workLoopConcurrent() {
    // Perform work until Scheduler asks us to yield
    while (workInProgress !== null && !shouldYield()) {
        performUnitOfWork(workInProgress);
    }
}


  shouldYield(...) --> Scheduler_shouldYield(...) --> unstable_shouldYield(...)
  --> shouldYieldToHost(...)
  --> getCurrentTime() >= deadline
  -->
    var yieldInterval = 5; var deadline = 0;
    var performWorkUntilDeadline = function() {
        ...
        var currentTime = getCurrentTime()
        deadline = currentTime + yieldInterval
        ...
    }